home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / mg2a_src.zip / SYS / AMIGA / CONSOLE.C < prev    next >
C/C++ Source or Header  |  1988-08-23  |  2KB  |  117 lines

  1. /*
  2.  * These functions are taken directly from the
  3.  * console.device chapter in the Amiga V1.1
  4.  * ROM Kernel Manual.
  5.  */
  6. #include <exec/types.h>
  7. #include <exec/io.h>
  8. #include <devices/console.h>
  9. #include <libraries/dos.h>
  10. #include <intuition/intuition.h>
  11.  
  12. extern    LONG    OpenDevice();
  13. extern    LONG    DoIO();
  14. extern    LONG    SendIO();
  15.  
  16. /*
  17.  * Open a console device, given a read request
  18.  * and a write request message.
  19.  */
  20.  
  21. int OpenConsole(writerequest,readrequest,window)
  22. struct IOStdReq *writerequest;
  23. struct IOStdReq *readrequest;
  24. struct Window *window;
  25. {
  26.     LONG error; 
  27.     writerequest->io_Data = (APTR) window;
  28.     writerequest->io_Length = (ULONG) sizeof(*window);
  29.     error = OpenDevice("console.device", 0L, writerequest, 0L);
  30.  
  31.     /* clone required parts of the request */
  32.     if (readrequest) {
  33.         readrequest->io_Device = writerequest->io_Device;
  34.         readrequest->io_Unit   = writerequest->io_Unit;
  35.     }
  36.     return((int) error);
  37. }
  38.  
  39. /*
  40.  * Output a single character    
  41.  * to a specified console
  42.  */ 
  43.  
  44. int ConPutChar(request,character)
  45. struct IOStdReq *request;
  46. char character;
  47. {
  48. #ifdef    V11
  49.     register int x;
  50. #endif
  51.     request->io_Command = CMD_WRITE;
  52.     request->io_Data = (APTR)&character;
  53.     request->io_Length = (ULONG)1;
  54.     DoIO(request);
  55.     /* caution: read comments in manual! */
  56.     return(0);
  57. }
  58.  
  59. /*
  60.  * Output a NULL-terminated string of
  61.  * characters to a console
  62.  */ 
  63.  
  64. int ConPutStr(request,string)
  65. struct IOStdReq *request;
  66. char *string;
  67. {
  68. #ifdef    V11
  69.     register int x;
  70. #endif
  71.     request->io_Command = CMD_WRITE;
  72.     request->io_Data = (APTR)string;
  73.     request->io_Length = (LONG)-1;
  74.     DoIO(request);
  75.     return(0);
  76. }
  77.  
  78. /*
  79.  * Write out a string of predetermined
  80.  * length to the console
  81.  */
  82.  
  83. int ConWrite(request,string,len)
  84. struct IOStdReq *request;
  85. char *string;
  86. int len;
  87. {
  88. #ifdef    V11
  89.     register int x;
  90. #endif
  91.     request->io_Command = CMD_WRITE;
  92.     request->io_Data = (APTR)string;
  93.     request->io_Length = (LONG)len;
  94.     DoIO(request);
  95.     return(0);
  96. }
  97.  
  98. /*
  99.  * Queue up a read request 
  100.  * to a console
  101.  */
  102.  
  103. int QueueRead(request,whereto)
  104. struct IOStdReq *request;
  105. char *whereto;
  106. {
  107. #ifdef    V11
  108.     register int x;
  109. #endif
  110.     request->io_Command = CMD_READ;
  111.     request->io_Data = (APTR)whereto;
  112.     request->io_Length = (LONG)1;
  113.     SendIO(request);
  114.     return(0);
  115. }
  116.  
  117.